package com.nineclock.sign.controller;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.PutObjectResult;
import com.nineclock.api.sign.SignControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.common.oss.OssProperties;
import com.nineclock.sign.dto.SignAllUserDTO;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.dto.SignPCListDTO;
import com.nineclock.sign.service.SignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class SignController implements SignControllerApi {
    @Autowired
    private SignService signService;

    //签到功能
    @PostMapping("/insert")
    public Result signInsert(SignDTO signDTO) throws IOException {
        signService.signInsert(signDTO);
        return Result.success();
    }
    //获取用户当天签到次数
    @GetMapping("/getDayCount")
    public Result<Integer> getDayCount() {
        Integer dayCountt = signService.getDayCount();
        return Result.success(dayCountt);
    }


    //导出签到列表
    @GetMapping("/export")
    @Override
    public void export(String startTime, String endTime) throws IOException {
        signService.export(startTime, endTime);
    }


    //PC端查询签到列表
    @Override
    @GetMapping("/sign")
    public Result<PageResult<SignPCListDTO>> querySignList(String startTime, String endTime,
                                                           @RequestParam(defaultValue = "1") Integer page,
                                                           @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<SignPCListDTO> signPcLists = signService.querySignList(startTime,endTime,page,pageSize);
        return Result.success(signPcLists);
    }

    //手机签到列表
    @Override
    @GetMapping("/listSignAllUser")
    public Result<List<SignAllUserDTO>> listSignAllUser(String dateStr) {
        List<SignAllUserDTO> signAllUserDTOS = signService.listSignAllUser(dateStr);
        return Result.success(signAllUserDTOS);
    }

    //获取当前用户当月签到记录
    @GetMapping("/pagingSignCurrentUserByMonth")
    public Result<List<SignDTO>> findCurrentUserByMonth(String dateStr){
        List<SignDTO> signs = signService.findCurrentUserByMonth(dateStr);
        return Result.success(signs);
    }
}
